package com.candicom.race.cars;

import java.awt.Image;
import java.awt.Point;
import javax.imageio.ImageIO;

public abstract class AbstractCar {

    protected double speed;
    protected int angle;
    private final Image image;
    private final CarModel model;
    private Point location;

    AbstractCar(CarModel _model, String _imageName) throws Exception {
        image = ImageIO.read(Object.class.getResource("/com/candicom/race/cars/images/" + _imageName));
        model = _model;
    }

    public abstract void speedUp();

    public abstract void slowDown();

    public abstract void turnRight();

    public abstract void turnLeft();

    public final void applyForce(double _force) {
        if (speed - _force < 0) {
            speed = 0;
        } else {
            speed -= _force;
        }
    }

    public final double getSpeed() {
        return speed;
    }

    public final int getAngle() {
        return angle;
    }

    public final void updateAngle(int _angle) {
        angle = _angle;
    }

    public final Point getLocation() {
        return location.getLocation();
    }

    public final void updateLocation(Point _loc) {
        location = _loc;
    }

    public final CarModel getModel() {
        return model;
    }

    public final Image getImage() {
        return image;
    }

    public final void reset() {
        speed = 0;
        angle = 0;        
        location = new Point(0, 0);
    }
}
